package cn.itcast.mq.listener;

import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class springRabbitMqListener {
//    @RabbitListener(queues = "simple.queue")
//    public void getqueue(String message){
//        System.out.println("获取simple.queue队列信息: "+message);
//    }

    @RabbitListener(queues = "fanout.queue1")
    public void getqueue2(String message){
        System.out.println("获取fanout.queue1队列信息: "+message);
    }

    @RabbitListener(queues = "fanout.queue2")
    public void getqueue3(String message){
        System.out.println("获取fanout.queue2队列信息: "+message);
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue("direct.queue1"),
            exchange = @Exchange(name = "itcast.direct",type = ExchangeTypes.DIRECT),
            key = {"blue","red"}
    ))
    public void getqueue4(String message){
        System.out.println("获取direct.queue1队列信息: "+message);
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue("direct.queue2"),
            exchange = @Exchange(name = "itcast.direct",type = ExchangeTypes.DIRECT),
            key = {"yellow","red"}
    ))
    public void getqueue5(String message){
        System.out.println("获取direct.queue2队列信息: "+message);
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue("topic.queue1"),
            exchange = @Exchange(name = "itcast.topic",type = ExchangeTypes.TOPIC),
            key = "china.#"
    ))
    public void getqueue6(String message){
        System.out.println("获取topic.queue1队列信息: "+message);
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue("topic.queue2"),
            exchange = @Exchange(name = "itcast.topic",type = ExchangeTypes.TOPIC),
            key = "#.news"
    ))
    public void getqueue7(String message){
        System.out.println("获取topic.queue2队列信息: "+message);
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue("topic.queue3"),
            exchange = @Exchange(name = "itcast.topic",type = ExchangeTypes.TOPIC),
            key = "#.work"
    ))
    public void getqueue8(String message){
        System.out.println("获取topic.queue3队列信息: "+message);
    }

    @RabbitListener(queues = "ll.queue1")
    public void getqueue9(Map<String,String> message){
        System.out.println("获取ll.queue1队列信息: "+message);
    }
}
